<template>
	<el-dialog title=""  visible :show-close="false" :append-to-body="true" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		<div class="bt">修改</div>
		<el-form label-width="100px" class="form">
			<el-form-item label="职位名称">
				<el-input v-model="form.mc" placeholder="请输入职位名称" class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="备注">
 				<el-input v-model="form.note" type="textarea"  :rows="4" placeholder="请输入备注" class="select-block"></el-input>
 			</el-form-item>
		</el-form>
		<el-button type="danger" class="submit" @click="deletewpfx()">删除</el-button>
		<el-button type="primary" class="submit" @click="submit">修改</el-button>
		<el-button type="primary" class="submit" @click="cancel">退出</el-button>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
		data() {
			return {
				id:'',
				form: {
					mc: '',
					note:'',
					id: ''
				}
			}
		},
		created() {
//			console.log(this.params,'wwwwwwwww')
			this.form.mc = this.params.mc;
			this.form.id = this.params.code;
			this.loadinfo();
		},
		methods: {
			loadinfo() {
				var logininfo = JSON.parse(localStorage.logininfo);
                var params2 = qs.stringify({
                 xxid:logininfo.xxid+'',
				 yhid:logininfo.id+'',
				 id:this.form.id+''
               })
             //执行
                 this.axios.post(this.$store.state.api + 'lstype/info',  params2 )
                 .then(res => {
                 this.form=res.data.data
                 this.id=res.data.data.code
                 }).catch(res => {
					this.$message.warning("服务器异常");
 			 		this.$emit('close', { type: 'info', cancel: true });
				})
			},
			deletewpfx() {
				this.$confirm('此操作将删除该分类, 是否继续?', '提示', {
				 confirmButtonText: '确定',
				 cancelButtonText: '取消',
				 type: 'warning'
			 }).then(() => {
				 var logininfo = JSON.parse(localStorage.logininfo);
 				var params3 = qs.stringify({
 					yhid: logininfo.id,
 					xxid: logininfo.xxid,
 					ids: this.form.id
 				});
 				this.axios.post(this.$store.state.api + 'lstype/deletepl', params3).then(res => {
 					if(res.data.code == 1) {
 						this.isLoading = false;
 						this.$emit('close', { type: 'fledit', cancel: false });
 						this.$message({
 							type: 'success',
 							message: '删除成功!'
 						});

 					} else {
 						this.$message({
 							type: 'error',
 							message: res.data.msg
 						});
 					}
 				}).catch(res => {
 					this.$store.state.loading = false;
 				})


			 }).catch(() => {
				 this.$message({
					 type: 'info',
					 message: '已取消'
				 });
			 });
			},
			submit() {
				//检测
				this.$store.state.loading = true;
				//装载数据
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					id: this.id,
					mc: this.form.mc,
					note: this.form.note,
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'lstype/update', params2)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'fledit', cancel: false });
							this.$store.state.loading = false;
							this.params.mc=this.form.mc;
						} else {
						    this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.warning("服务器异常");
						this.$store.state.loading = false;
					})
			},
			cancel() {
				this.$emit('close', { type: 'fledit', cancel: true })
			}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		text-align: center;
	}
	.bt {
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		margin-bottom: 20px;
		color: white;
		text-align: left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}
	.form {
		text-align: center;
		margin-top: 20px;
	}
	.input {
		display: inline-block;
	}
	.select-block {
		display: block;
	}
	.submit {
		width: 120px;
	}
</style>
